package com.zhuzhumail.utils;




import com.zhuzhumail.entity.KqAbsenceDutyVo;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
 * 去掉null值
 */
public class ArrayUtils {
    public static KqAbsenceDutyVo[] deleteArrayNull(KqAbsenceDutyVo[] kqAbsenceDutyVos2) {
        KqAbsenceDutyVo[] kqAbsenceDutyVos = kqAbsenceDutyVos2;
// 声明一个list
        List<KqAbsenceDutyVo> list = new ArrayList<>(kqAbsenceDutyVos2.length);
        for (KqAbsenceDutyVo str : kqAbsenceDutyVos) {
            list.add(str);
        }

        // 删除空的值
        while (list.remove(null)) ;
        while (list.remove("")) ;

// 将list 转换成数组
        KqAbsenceDutyVo[] list2 = (KqAbsenceDutyVo[]) list.toArray(new KqAbsenceDutyVo[]{new KqAbsenceDutyVo()});
// 返回删除空值后的数组
        return list2;
    }

    public static void main(String[] args) {
        KqAbsenceDutyVo [] kqAbsenceDutyVos=new KqAbsenceDutyVo[38];
        KqAbsenceDutyVo kqAbsenceDutyVo=new  KqAbsenceDutyVo();
        kqAbsenceDutyVo.setAttendanceDay(1);
        kqAbsenceDutyVos[2]=kqAbsenceDutyVo;
        KqAbsenceDutyVo[] kqAbsenceDutyVos1 = ArrayUtils.deleteArrayNull(kqAbsenceDutyVos);
        for (KqAbsenceDutyVo absenceDutyVo : kqAbsenceDutyVos1) {
            System.out.println(absenceDutyVo.toString());
        }
    }

    /**
     * 根据下标删除数组的元素
     * @return
     */
    public static Object[] IndexDeleteArrayElements(Object[] objects,Integer index){
        Object [] newArr = new Object[objects.length - 1];
        //定义新数组的索引newArr
        int j = 0;
        //for循环将未删除的元素按原保存顺序保存到新数组
        for (int i = 0; i < objects.length; i++) {
            //判断数组arr中需删除的索引index与循环到的i是否相同,不同时持续赋值j++,相同时则跳过继续比较
            if (index != i) {
                //index不等于i持续赋值
                newArr[j] = objects[i];
                //newArr[]向后移动一个元素
                j++;
            }
        }
        //输出新数组newArr
        System.out.println(Arrays.toString(newArr));
        return newArr;

    }
    public static Object[] deleteArrayNull(Object[] kqAbsenceDutyVos2) {
        Object[] kqAbsenceDutyVos = kqAbsenceDutyVos2;
// 声明一个list
        List<Object> list = new ArrayList<>(kqAbsenceDutyVos2.length);
        for (Object str : kqAbsenceDutyVos) {
            list.add(str);
        }

        // 删除空的值
        while (list.remove(null)) ;
        while (list.remove("")) ;

// 将list 转换成数组
       Object[] list2 = (Object[]) list.toArray(new Object[]{new Object()});
// 返回删除空值后的数组
        return list2;
    }




}
